//pack11jsclass

var NewPropertyPopup = new newPropertyPopup();

function newPropertyPopup() {

    this.initialized=false;
    this.element=document.getElementById("PopupBody");
    this.form=document.getElementById("PopupBody");
    this.extra=document.getElementById("PopupBody");
    this.newPropertyType=0;

    this.open = function() {
        if(!this.initialized) this.init();
        if(!this.initialized) return;

        fields=NewPropertyPopup.element.getElementsByTagName("input");
        for(lng=0; lng<fields.length; lng++) {
            if(fields[lng].className=="textinput") {
               fields[lng].value="";
            }
        }

        this.element.style.display="block";
        PopupManager.container.style.display="block";
        PopupManager.currentPopup=this;
        PopupManager.popupActive=true;
    }

    this.init = function() {

        try {
            this.element=document.getElementById("NewPropertyPopup");
        } catch(e) {
            Trace("Could not find NewPropertyPopup");
            return;
        }

        buttons=this.element.getElementsByTagName("input");
        for(tpb=0; tpb<buttons.length; tpb++) {
            button=buttons[tpb];
            if(button.id=="NewPropertySubmit") {
                button.onclick=this.submit;
            }

            if(button.id=="NewPropertyCancel") {
                button.onclick=function() {
                PopupManager.close();
                }
            }
        }

        this.initialized=true;
    }

    this.submit = function() {
        if(AjaxManager.locked) return;
        fields=NewPropertyPopup.element.getElementsByTagName("input");
        checker=0;
        for(lng=0; lng<fields.length; lng++) {
            if(fields[lng].className=="textinput") {
                //alert(fields[lng].value+" - "+fields[lng].value.length);
                if(fields[lng].value.length>1) {
                    lang=new ajaxVar();
                    lang.name=fields[lng].name;
                    lang.value=fields[lng].value;
                    AjaxManager.variables.push(lang.query());
                    Trace(lang.name+" "+lang.value);
                    checker++;
                }
            }

            if(fields[lng].name=="type" && fields[lng].checked) {
                lang=new ajaxVar();
                lang.name=fields[lng].name;
                lang.value=fields[lng].value;
                AjaxManager.variables.push(lang.query());
                Trace(lang.name+" "+lang.value);
                NewPropertyPopup.newPropertyType=fields[lng].value;
            }
        }

        lang=new ajaxVar();
        lang.name="group";
        lang.value=document.getElementById("NewPropertyGroup_select").value;
        AjaxManager.variables.push(lang.query());
        Trace(lang.name+" "+lang.value);

        if(checker==0) {
            alert("Надо заполнить хотя бы одно поле\n А лучше все :-)");
            return;
        }

        lang=new ajaxVar();
        lang.name="lang";
        lang.value=document.getElementById("languageID").value;
        AjaxManager.variables.push(lang.query());

        objID=new ajaxVar();
        objID.name="object";
        objID.value=document.getElementById("object_id").value;
        AjaxManager.variables.push(objID.query());

        AjaxManager.url="?response=NewPropertyResponder";
        AjaxManager.backHandler=NewPropertyPopup.ajaxHandler;
        document.getElementById("NewPropertyPopupLoader").innerHTML=AjaxManager.loader;
        AjaxManager.callServer();
    }

    this.ajaxHandler = function(text,xml) {
        if(NewPropertyPopup.newPropertyType==4) {
            document.getElementById("PhotosContainer2").innerHTML+=text;
        } else {
            document.getElementById("AdminObjectContainer").innerHTML+=text;
        }
        PopupManager.close();
    }

}